﻿using System;
using System.Data.SqlClient;

namespace Project.dalSql
{
    public class dalSqlTransaction : MarshalByRefObject
    {
        public SqlConnection Connection = null;
        public SqlTransaction Transaction = null;

        public dalSqlTransaction()
        {
            Connection = new SqlConnection(dalSqlBaseCommandHelper.ConnectionString);
        }
        public void BeginTransaction()
        {
            if (Connection != null)
            {
                Connection.Open();
                Transaction = Connection.BeginTransaction();
            }
        }

        public void Commit()
        {
            if (Transaction != null)
            {
                Transaction.Commit();
                Connection.Close();
                Transaction = null;
            }
        }

        public void Rollback()
        {
            if (Transaction != null)
            {
                Transaction.Rollback();
                Connection.Close();
                Transaction = null;
            }
        }

        public void Close()
        {
            Connection.Close();
        }

        public void Open()
        {
            Connection.Open();
        }


    }
}
